<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>订单管理</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css" />
		<link rel="stylesheet" href="style/css/agent_order.css" />
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="style/mockjs/dist/mock.js"></script>
		<script type="text/javascript" src="style/js/vue.min.js"></script>
		<script type="text/javascript" src="style/js/vue-resource.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>
		<style>
			.tab .tab25 li{
				width:25%
			}
			.tab .tab25 li a{
				font-size:14px;
			}
			.mui-pull-top-pocket{
				display:none !important;
			}
		</style>
	</head>

	<body>
		<!--header-->
		<div id="header">
			<h1>订单管理</h1>
			<span class="backicon"></span>
		</div>
		<!--content-->
		<div class="body" id="order_manage">

			<div class="tab">
				<ul class="top clearfix tab25">
					<!--<li :class="{'clickStyle':flag==0}" @tap="allOrder">
						<a href="javascript:;" >全部</a>
					</li>-->
					<li :class="{'clickStyle':flag==0}" @tap="needPay">
						<a href="javascript:;">待付款</a>
					</li>
					<li :class="{'clickStyle':flag==1}" @tap="alreadyPay">
						<a href="javascript:;">已付款</a>
					</li> 
					<li :class="{'clickStyle':flag==2}" @tap="needStor">
						<a href="javascript:;" >已入库</a>
					</li>
					<li :class="{'clickStyle':flag==3}" @tap="needWrite">
						<a href="javascript:;">待核销</a>
					</li>
				</ul>
				<div class="tabcontent">
					<!--<div v-if="flag==0">
						<div class="order_list" v-for="(allList,index) in allgoods" v-if="allgoods!=''">
							<div class="row">
								<div class="col order-id">
									<div class="row row-align">
										<div class="ellipsis">
											<span>订单号 {{allList.order_no}}</span></div>
										<div class="store-icons"></div>
									</div>
								</div>
								<div class="order-txt text_color" style="width:50px">{{allList.status==0?"待付款":(allList.status==1?"已付款":(allList.status==2?"已入库":"待核销"))}}</div>
							</div>
							<div class="product_wrap">
								<div class="item-row row" v-for="item in allList.good_list">
									<img :src="htp+item.thumb_pic">
									<div class="title">{{item.title}}</div>
									<div class="price">
										<div>¥{{item.price}}</div>
										<div style="color: #999;">x<em>{{item.num}}{{item.unit}}</em></div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col status-span">
									<span style="color: #999;">共 {{allList.num}} 件</span>
									<span style="color: #999;">合计</span>
									<span>¥{{allList.price}}</span>
								</div>
							</div>
						</div>

					</div>-->
					<div class="waitpay" v-if="flag==0">
						<div class="order_list" v-for="(pay,index) in needPayList" v-if="needPayList!=''">
							<div class="row">
								<div class="col order-id">
									<div class="row row-align">
										<div class="ellipsis">
											<span>订单号 {{pay.order_no}}</span></div>
										<div class="store-icons"></div>
									</div>
								</div>
								<!--<div class="col order-txt text_color">{{pay.status}}</div>-->
							</div>
							<div class="product_wrap">
								<div class="item-row row" v-for="item in pay.good_list">
									<img :src="htp+item.thumb_pic">
									<div class="title">{{item.title}}</div>
									<div class="price">
										<div>¥{{item.price}}</div>
										<div style="color: #999;">x<em>{{item.num}}{{item.unit}}</em></div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col status-span">
									<span style="color: #999;">共 {{pay.num}}件</span>
									<span style="color: #999;">合计</span>
									<span>¥{{sump[index]}}</span>
								</div>
							</div>
						</div>
					</div>
					<div class="needstor" v-if="flag==1">
						<div class="order_list" v-for="(alrdy,index) in alreadyList" v-if="alreadyList!=''">
							<div class="row">
								<div class="col order-id">
									<div class="row row-align">
										<div class="ellipsis">
											<span>订单号 {{alrdy.order_no}}</span></div>
										<div class="store-icons"></div>
									</div>
								</div>
								<!--<div class="col order-txt text_color">{{alrdy.status}}</div>-->
							</div>
							<div class="product_wrap">
								<div class="item-row row" v-for="item in alrdy.good_list">
									<img :src="htp+item.thumb_pic">
									<div class="title">{{item.title}}</div>
									<div class="price">
										<div>¥{{item.price}}</div>
										<div style="color: #999;">x<em>{{item.num}}{{item.unit}}</em></div>
									</div>
								</div>
								
							</div>
							<div class="row">
								<div class="col status-span">
									<span style="color: #999;">共{{alrdy.num}} 件</span>
									<span style="color: #999;">合计</span>
									<span>¥{{alrdy.price}}</span>
								</div>
							</div>
							<!--<div class="status-navigator">
								<div class="box box-rl">
									<div class="status-btn-red" @tap="storin(index)">去入库</div>
									<div class="status-btn-default">取消订单</div>
								</div>
							</div>-->
						</div>
					</div>
					<div class="needstor" v-if="flag==2">
						<div class="order_list" v-for="(nstore,index) in needStorList" v-if="needStorList!=''">
							<div class="row">
								<div class="col order-id">
									<div class="row row-align">
										<div class="ellipsis">
											<span>订单号 {{nstore.order_no}}</span></div>
										<div class="store-icons"></div>
									</div>
								</div>
								<!--<div class="col order-txt text_color">{{nstore.status}}</div>-->
							</div>
							<div class="product_wrap">
								<div class="item-row row" v-for="item in nstore.good_list">
									<img :src="htp+item.thumb_pic">
									<div class="title">{{item.title}}</div>
									<div class="price">
										<div>¥{{item.price}}</div>
										<div style="color: #999;">x<em>{{item.num}}{{item.unit}}</em></div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col status-span">
									<span style="color: #999;">共{{nstore.num}} 件</span>
									<span style="color: #999;">合计</span>
									<span>¥{{nstore.price}}</span>
								</div>
							</div> 
						</div>
					</div>
					<div class="needwrite" v-if="flag==3">
						<div class="order_list" v-for="(nwrite,index) in needWriteList" v-if="needWriteList!=''">
							<div class="row">
								<div class="col order-id">
									<div class="row row-align">
										<div class="ellipsis">
											<span>订单号 {{nwrite.order_no}}</span></div>
										<div class="store-icons"></div>
									</div>
								</div>
								<!--<div class="col order-txt text_color">{{nwrite.status}}</div>-->
							</div>
							<div class="product_wrap">
								<div class="item-row row" v-for="item in nwrite.good_list">
									<img :src="htp+item.thumb_pic">
									<div class="title">{{item.title}}</div>
									<div class="price">
										<div>¥{{item.price}}</div>
										<div style="color: #999;">x<em>{{item.num}}{{item.unit}}</em></div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col status-span">
									<span style="color: #999;">共{{nwrite.num}} 件</span>
									<span style="color: #999;">合计</span>
									<span>¥{{nwrite.price}}</span>
								</div>
							</div>
							<!--<div class="status-navigator">
								<div class="box box-rl">
									<div class="status-btn-red" @tap="hexiao(index)">去核销</div>
									<!--<div class="status-btn-default">取消订单</div>
								</div>
							</div>-->
						</div>
					</div>
				</div>

			</div>

		</div>
        <script>
		    new Vue({
		    	el:'#order_manage',
		    	data:{
		    		flag:0,
		    		allgoods:"",
		    		alreadyList:"",
		    		needPayList:"",
		    		needStorList:"",
		    		needWriteList:"",
		    		agentno:'',
		    		htp:"",
		    		ticket:"",
				    sign:"",
				    sump:[]
		    	},
		    	methods:{
		    		allOrder:function(){
		    			this.flag=0
		    			var that=this;
		    			this.pullist(0,"allgoods")
		    		},
		    		alreadyPay:function(){
		    			this.flag=1
		    			var that=this; 
		    			this.pullist(1,"alreadyList")
		    		},
		    		needPay:function(){
		    			this.flag=0
		    			var that=this;
		    			this.pullist(0,"needPayList")
		    		},
		    		needStor:function(){
		    			this.flag=2
		    			var that=this;
		    			this.pullist(2,"needStorList")
		    		},
		    		needWrite:function(){
		    			this.flag=3
		    			var that=this; 
		    			this.pullist(3,"needWriteList")
		    		},
		    		hexiao:function(hIndex){
		    			this.$http.post(domain+"/saler/setScanAgent?t="+this.ticket+"&sign="+this.sign,{
						      	agent_no:this.agentno,
						      	order_no:this.needStorList[hIndex].order_no
						      },{emulateJSON:true}).then(
					            function (res) {
					                // 处理成功的结果
					                console.log(res.body)
					                if(res.body.code==1){
					                    openurl("scan_out")
					                }else{
					                	mui.toast("无法核销")
					                }
					            },function (res) {
					            // 处理失败的结果
					            console.log(res) 
					            }
					        )
		    		},
		    		storin:function(sIndex){
		    			this.$http.post(domain+"/saler/setScanAgent?t="+this.ticket+"&sign="+this.sign,{
						      	agent_no:this.agentno,
						      	order_no:this.alreadyList[sIndex].order_no
						      },{emulateJSON:true}).then(
					            function (res) {
					                // 处理成功的结果
//					                alert(this.alreadyList[sIndex].order_no)
					                console.log(res.body)
					                if(res.body.code==1){
					                    openurl("scan_in")
					                }else{
					                	mui.toast("无法入库")
					                }
					            },function (res) {
					            // 处理失败的结果
					            console.log(res) 
					            }
					        )
		    		},
		    		pullist:function(i,l){
		    			var p=1;
						var that=this;
						var i=i,l=l
						mui.plusReady(function(){						    
						    
						    that.$http.post(domain+"/saler/getOrderList?t="+that.ticket+"&sign="+that.sign,{
						      	page:p,
						      	agent_no:that.agentno,
						      	type:i
						      },{emulateJSON:true}).then(
					            function (res) {
					                // 处理成功的结果
					                console.log(res.body)
					                if(res.body.code==1){
					                  that[l]=res.body.data.list;
					                  console.log(l)
					                  console.log(that[l])
					                  if(res.body.data.list.length==0){
					                	mui.toast("没有更多了")
					                	p=1
					                  } 
					                }else{
					                	mui.toast("暂无商品")
					                }
					            },function (res) {
					            // 处理失败的结果
					            console.log(res) 
					            }
					        )
						})
							
		    		}
		    	}, 
		    	created:function(){
		            this.ticket=localStorage.getItem("tick")
                    this.sign=localStorage.getItem("sig")
		    	},
		    	mounted:function(){
		    		var that=this; 
		    	    var p=1;
		    	    that.htp=domain2
		    	    mui.plusReady(function(){
		    	    	that.agentno=plus.webview.currentWebview().mem;
		    	    	that.flag=plus.webview.currentWebview().cur
		    	    	that.$http.post(domain+"/saler/getOrderList?t="+that.ticket+"&sign="+that.sign,{ 
					      	page:p,
					      	agent_no:that.agentno,
					      	type:that.flag
					      },{emulateJSON:true}).then( 
				            function (res) {
				                // 处理成功的结果
				                console.log(res.body)
				               that.sump=[];
				                for(var i=0;i<res.body.data.list.length;i++){
				                	that.sump[i]=0
				                	for(var j=0;j<res.body.data.list[i].good_list.length;j++){
				                		that.sump[i]+=parseFloat(res.body.data.list[i].good_list[j].price)
				                	}
				                }
//				                alert(that.sump[0])
				                if(res.body.code==1){
//				                	if(that.flag==0){that.allgoods=res.body.data.list;}
				                	if(that.flag==0){that.needPayList=res.body.data.list;}
				                	if(that.flag==1){that.alreadyList=res.body.data.list;}
				                	if(that.flag==2){that.needStorList=res.body.data.list;}
				                	if(that.flag==3){that.needWriteList=res.body.data.list;}
				                  if(res.body.data.list.length==0){
				                	mui.toast("没有更多了")
				                	p=1
				                  }
				                }else{
				                	mui.toast("暂无商品")
				                }
				            },function (res) {
				            // 处理失败的结果
				            console.log(res) 
				            }
				        )
		    	    })
                    
		    	}
		   }) 
	    </script>
	</body>
	

</html>
